package com.audaque.springboot.foshanupload.web.datamongodbmodeldemo.model.pojo;

import com.fasterxml.jackson.annotation.JsonFormat;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.mongodb.morphia.annotations.Entity;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)


@Entity
@Document(collection = "user")
public class User implements Serializable  {

  @Id
  private String id;

  @NotNull
  @Size(min = 2, max = 20)
  private String username;

  private String name;

  private Integer age;

  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  @CreatedDate
  private Date createdDate;

  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  @LastModifiedDate
  private Date lastModifiedDate;

  @DBRef
  private Role role;

}
